define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wx/wxorderinfo/index',
                    add_url: 'wx/wxorderinfo/add/ids/'+order_sn,
                    edit_url: 'wx/wxorderinfo/edit',
                    del_url: 'wx/wxorderinfo/del',
                    multi_url: 'wx/wxorderinfo/multi',
                    table: 'wxorderinfo',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_sn', title: __('Order_sn')},
                        {field: 'wxproduct_id', title: __('Wxproduct_id'),formatter:function (value,row,index) {
                            if(row.dk)
                            {
                              return value+'('+row.dk+')';
                            }
                            return value;

                          }},
                        {field: 'kg', title: __('Kg')},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'wxorder.receipt', title: __('Wxorder.receipt')},
                        {field: 'wxorder.phone', title: __('Wxorder.phone')},
                        {field: 'wxorder.address', title: __('Wxorder.address')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                queryParams: function (params) {
                  //这里可以追加搜索条件
                  var filter = JSON.parse(params.filter);
                  var op = JSON.parse(params.op);
                  //这里可以动态赋值，比如从URL中获取admin_id的值，filter.admin_id=Fast.api.query('admin_id');
                  filter.order_sn = order_sn;
                  op.order_sn = "=";
                  params.filter = JSON.stringify(filter);
                  params.op = JSON.stringify(op);
                  return params;
                },
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});